package ldh.serialize.register;

public class RegisterKey {

	private Class<?> clazz;
	private String name;
	
	public RegisterKey(Class<?> clazz) {
		this(clazz, null);
	}
	
	public RegisterKey(String name) {
		this(null, name);
	}
	
	public RegisterKey(Class<?> clazz, String name) {
		this.clazz = clazz;
		this.name = name;
	}

	public Class<?> getClazz() {
		return clazz;
	}

	public void setClazz(Class<?> clazz) {
		this.clazz = clazz;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public boolean equals(Object o) {
		if (o == null || !(o instanceof RegisterKey)) {
			return false;
		}
		RegisterKey rk = (RegisterKey) o;
		if (clazz != null && rk.getClazz() != null && rk.getClazz() == this.getClazz()) {
			return true;
		}
		if (name != null && name.equals(rk.getName())) {
			return true;
		}
		return false;
	}
	
	public int hashCode() {
		int t = 13;
		if (clazz != null) {
			t *= clazz.hashCode();
		}
		if (name != null) {
			t *= name.hashCode();
		}
		return t;
	}
}
